package dao.impl;

import hibernate.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import dao.ProveedorDAO;
import dominio.Proveedor;


public class ProveedorDAOImpl implements ProveedorDAO{

	private static ProveedorDAOImpl instancia = null;
	@SuppressWarnings("unused")
	private static SessionFactory sf = null;

	private ProveedorDAOImpl(){}
	
	public static ProveedorDAOImpl getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new ProveedorDAOImpl();
		} 
		return instancia;
	}
	
	public Proveedor findByID(Integer id){
		Proveedor proveedor = new Proveedor();
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx= session.beginTransaction();
		session.load(proveedor, id);
		tx.commit();
		session.close();
		return proveedor;
	}
}
